import org.junit.*;
import org.junit.Before;
import java.util.Date;

import play.test.*;
import play.mvc.*;
import play.mvc.Http.*;
import models.*;


public class foudaTestViews extends FunctionalTest{
	
	@Before
	public void setup() {
		Fixtures.deleteAll();
	}
	
	@Test
	public void testMemberRemoval(){
		
		Organization org = new Organization ("org1", "first organization", 0);
		org.save();
		EEntity entity = new EEntity ("ent1", "first entity", org);
		entity.save();
		User user = new User("omar", "male", "oFouda", "123", new Date(), "o-s-f@hotmal", "12343");
		user.save();
		User user2 = new User("ahmed","male","aa","11",new Date(), "adsAD", "dadad");
		user2.save();
		Topic topic = new Topic("topic", 1, "asss", new Date(), entity, user2);
		topic.save();
		entity.topics.add(topic);
		entity.save();
		
		Role role = new Role ("OrganizationLead");
		role.save();
		RoleInEntity userRoleEntity = new RoleInEntity (entity, user, role);
		userRoleEntity.save();
		
		entity.followingUsers.add(user);
		entity.save();
		user.followedEnts.add(entity);
		user.followedTopics.add(topic);
		user.save();
		topic.followingUsers.add(user);
		topic.save();
		
		
		assertNotNull(org); assertNotNull(entity); assertNotNull(user); assertNotNull(user2);
		assertNotNull(topic); assertNotNull(role); assertNotNull(userRoleEntity);
		
		assertEquals(true, entity.followingUsers.contains(user));
		assertEquals(true, user.followedEnts.contains(entity));
		assertEquals(true, user.followedTopics.contains(topic));
		assertEquals(true, entity.topics.get(0).followingUsers.contains(user));
		

		entity.removeMember(user.id);
		
		assertEquals(false, entity.followingUsers.contains(user));
		assertEquals(false, user.followedEnts.contains(entity));
		assertEquals(false, user.followedTopics.contains(topic));
		assertEquals(false, topic.followingUsers.contains(user));
		
	}

}
